{include file="public/header" /}
<article class="page-container">
    <form action="" method="post" class="form form-horizontal" enctype="multipart/form-data" id="form-add">
        <div class="row cl">
            <label class="form-label col-xs-5 col-sm-5"><span class="c-red">*</span>订单编号：</label>
            <div class="formControls col-xs-5 col-sm-5">
                <input type="text" class="input-text" value="{$data.sell_sn|default=''}" placeholder="" id="sn" name="sn" readonly>
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-5 col-sm-5">
                <span class="c-red">*</span>订单类型：</label>
            <div class="formControls col-xs-5 col-sm-5">
                {switch name="$data.sell_type"}
                    {case value="1"}
                     <input type="text" class="input-text" value="平台放单" placeholder="" readonly>
                    {/case}
                    {case value="2"}
                    <input type="text" class="input-text" value="换购订单" placeholder=""  readonly>{/case}
                    {case value="3"} <input type="text" class="input-text" value="用户订单" placeholder=""  readonly>{/case}
                    {default /}<input type="text" class="input-text" value="未知" placeholder=""  readonly>
                {/switch}
            </div>
            <div class="col-4"> </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-5 col-sm-5">
                <span class="c-red">*</span>用户名：</label>
            <div class="formControls col-xs-5 col-sm-5">
                <input type="text" class="input-text" value="{$data.sell_user_name|default=''}" readonly >
            </div>
            <div class="col-4"> </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-5 col-sm-5">
                <span class="c-red">*</span>手机号：</label>
            <div class="formControls col-xs-5 col-sm-5">
                <input type="text"  class="input-text" value="{$data.sell_mobile|default=''}" readonly >
            </div>
            <div class="col-4"> </div>
        </div>
        <div class="row cl" >
            <label class="form-label col-xs-5 col-sm-5"><span class="c-red">*</span>类型：</label>
            <div class="formControls col-xs-5 col-sm-5">
                <select name="pay_bank" class="select" id="pay_bank">
                    {foreach $banks as $v}
                        {switch name="$v.type"}
                            {case value="1"}
                                <option type="1" value="{$v.id}" >支付宝</option>
                            {/case}
                            {case value="2"}
                                <option type="2" value="{$v.id}" >微信</option>   {/case}
                            {case value="3"}
                                 <option  type="3" value="{$v.id}" >银行卡</option>
                                {/case}
                            {default /}
                        {/switch}
                    {/foreach}
                </select>

            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-5 col-sm-5">
                <span class="c-red">*</span>账号|卡号：</label>
            <div class="formControls col-xs-5 col-sm-5">
                <input type="text" maxlength="10" class="input-text" value="" readonly disabled id="bank_account">
            </div>
            <div class="col-4"> </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-5 col-sm-5">
                <span class="c-red">*</span>收款人姓名：</label>
            <div class="formControls col-xs-5 col-sm-5">
                <input type="text" maxlength="10" class="input-text" value="" readonly disabled id="bank_user_name">
            </div>
            <div class="col-4"> </div>
        </div>
        <div class="row cl" id="bank_qrcode_div">
            <label class="form-label col-xs-5 col-sm-5">
                <span class="c-red">*</span>收款人码：</label>
            <div class="formControls col-xs-5 col-sm-5">
                <img  id="bank_qrcode" style="width: 100%;height: 200px" >
            </div>
            <div class="col-4"> </div>
        </div>
        <div class="row cl" id="bank_info_div">
            <label class="form-label col-xs-5 col-sm-5">
                <span class="c-red">*</span>银行卡信息：</label>
            <div class="formControls col-xs-5 col-sm-5">
                <input type="text" maxlength="10" class="input-text" value="" readonly disabled id="bank_info">
            </div>
            <div class="col-4"> </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-5 col-sm-5"><span class="c-red">*</span>支付凭证：</label>
            <div class="file">
                <span>选择图片</span>
                <input type="file"  datatype="*" nullmsg="商品图片不能为空" onchange="upload();" id="photoFile">
                <input type="hidden" name="pay_img"  id="pic">
            </div>
            <img id="preview_photo" width="200px" height="200px">
        </div>
        <div class="row cl">
            <div class="col-xs-5 col-sm-5 col-xs-offset-4 col-sm-offset-3">
                <input type="hidden" value="{$data.id|default=''}" name="id">
                <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>


{include file="public/footer" /}
<script type="text/javascript">
    $(function(){

        $("#form-add").validate({
            rules:{

            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                $(form).ajaxSubmit({
                    success:function(data){
                        console.log(data);
                        if(data.status == 0){
                            layer.msg("操作成功",{icon:1,time:1000,shade: [0.3, '#000']},function(){
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.location.reload();
                                parent.layer.close(index);
                            });
                        }else{
                            layer.msg(data.info,{icon:2,time:1000,shade: [0.3, '#000']});
                        }
                    },
                    error:function(error){
                        layer.msg('系统发生了错误',{icon:2,time:3000,shade: [0.5, '#FF0000']});
                    }
                });
            }
        });
    });
    var banks = eval('<?php echo json_encode($banks);?>');


    $("#pay_bank").change(function(){
        var id =  $("#pay_bank").val()
        initUiByPayType(getBank(id))
    });

    var getBank= function(id){
        for (var index in banks){
            if (banks[index].id = id){
                return banks[index];
            }
        }
    }

    var initUiByPayType = function(bank){

        if (bank.type!=3){
            $("#bank_info_div").hide()
            $("#bank_qrcode_div").show()
            $("#bank_qrcode").attr("src",bank.img_url)
        }else {
            $("#bank_info_div").show()
            $("#bank_qrcode_div").hide()
            $("#bank_info").val("银行:"+bank.bank_name+":支行"+bank.bank_brach_name)

        }
        $("#bank_account").val(bank.account)
        $("#bank_user_name").val(bank.user_name)

    }
    var options =  $('#pay_bank').find("option");
    options.attr("selected", false);
    options.first().attr("selected", true);
    initUiByPayType(banks[0])


    function upload() {
        if ($("#photoFile").val() == '') {
            layer.msg('请选择上传文件');
        }
        var formData = new FormData();
        formData.append('photo', document.getElementById('photoFile').files[0]);
        $.ajax({
            url:"{:url('/shop/uploadField')}",
            type:"post",
            data: formData,
            contentType: false,
            processData: false,
            success: function(data) {
                if (data.status == 1) {
                    $("#preview_photo").attr('src',data.data['save_name']);
                    $("#pic").val(data.pic);
                    layer.msg(data.msg);
                } else if(data.status == 2) {
                    $("#preview_photo").attr('src',data.data);
                    $("#pic").val(data.pic);
                    layer.msg(data.msg);
                }else{
                    alert(data.msg);

                }
            },
            error:function(data) {
                alert("上传失败")
            }
        });
    }
</script>
